Skip to content

Leave an exact power too large to build written, never +oo or 0 - #2437

Open
Rafael-SOWNet wants to merge 1 commit into
masterfrom
feature/a-power-too-large-to-build-is-not-infinite
Open

Rafael-SOWNet wants to merge 1 commit into
masterfrom
feature/a-power-too-large-to-build-is-not-infinite

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Part of #1448.

Since #2347, an exact power too large to build (past 2^24 bits) evaluated as a decimal. 2^(10^9) became +oo, and 2^(-(10^9)) became 0. 2.6.0 hung on these. A guard kept Simplify from collapsing the bare power to +oo, but differences, products and comparisons took the decimal, so they answered NaN or the wrong truth value for numbers that exist.

Now:

  • The power stays written, in Evaled as in Simplify, and so for rational exponents: 8^(10^9/3) was +oo too. Subtraction, 0 * a and 2^m / 2^n then come out right from the existing rules.

  • Comparisons with such a power are decided in three ways, and otherwise left undecided:

    • exactly by the exponents, for two powers of one positive base;
    • by the signs, using the exponent's parity for a negative base;
    • by the logarithms of the magnitudes at 120 digits, only where they differ by more than 1e-90 of their size.

    Two magnitudes that may be equal are never told apart, so 2^(10^9) = 4^(5*10^8) stays written. It was True on master only because +oo = +oo.

#1448's thread asked for a decimal approximation from Evaled, and measured that today's decimals overflow to +oo. That approximation needs the v3 numerics, so #1448 stays open for it.

Expression 2.6.0 master this branch true
eval 2^(10^9) hangs +oo 2 ^ 1000000000 (as written)
eval 2^(-(10^9)) hangs 0 2 ^ (-1000000000) (as written)
simplify 2^(10^9) - 2^(10^9) hangs NaN 0 0
simplify 2^(10^9)/2^(10^9 - 1) hangs NaN 2 2
simplify 2^(10^9) * 2^(-(10^9)) hangs NaN 1 1
eval 0 * 2^(10^9) hangs NaN 0 0
eval 2^(10^9) > 2^(10^9 - 1) hangs False True True
simplify 2^(-(10^9)) > 0 hangs False True True
eval 2^(10^9) = 2^(10^9 - 1) hangs True False False
eval 3^(10^9) > 2^(10^9) hangs False True True
eval 2^(10^9) = 4^(5*10^8) hangs True undecided True
eval 46655^(10^20) hangs +oo written finite
eval forall n in ZZ* : 3^(n+1) divides 2^(3^n)+1 hangs as written as written unsettled

All of #2347's former hang cases finish in 175–291 ms, among them simplify (x^x - 1)^(e^(e^x)), simplify 2^(10^10) and simplify 46655^(10^20) + 1. #2347's unshipped BREAKING-CHANGES.md entry is replaced by "An exact power too large to build is left written", measured from 2.6.0 to now.

Not changed, because both come from the decimal context's exponent range, which the v3 numerics own:

  • 2^(10^7 + 0.5), whose exponent is a decimal;
  • (3+4i)^2000, which is +oo + +ooi on master and NaN on 2.6.0.

Checked on this branch:

  • Tests: UnitTests 19441 passed, plus the MCP, Terminal, InteractiveWrapper and F# wrapper suites, and the AOT smoke test. The rewritten AnExactPowerTooLargeToBuildTest has 42 cases, 21 of which fail on master.
  • Harnesses: BoundCheck, RootCheck, CasBench, PropCheck, SimpSweep, RuleCheck, CanonCheck and Confluence all pass.

🤖 Generated with Claude Code

Past 2^24 bits an exact power was evaluated as the decimal, which is +oo past
the context's range and 0 below it. A finite nonzero number became an
infinity or a zero and fed exact arithmetic: 2^(10^9) - 2^(10^9) and
0 * 2^(10^9) were NaN, 2^(10^9)/2^(10^9 - 1) was NaN, 2^(10^9) > 2^(10^9 - 1)
and 2^(-(10^9)) > 0 were False, and 2^(10^9) = 2^(10^9 - 1) was True.

Evaluating the power node now leaves it written, for whole and rational
exponents, so a Powf of an exact base never reaches the decimal. What holds
it is settled by structure (a - a, 0 * a) or by exponent arithmetic
(2^m / 2^n), as Simplify already does. A comparison with such a power is
decided by the signs, by the exponents for one positive base, or by the
logarithms of the magnitudes where they differ by more than 1e-90 of their
size, computed at 120 digits. Anything else stays written:
2^(10^9) = 4^(5 * 10^8) is no longer decided. EvalNumerical refuses the
power with CannotEvalException. Every row hung on 2.6.0 and none hangs here.

Part of #1448.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.74468% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.86%. Comparing base (4949e4c) to head (ebca5ff).

Files with missing lines Patch % Lines
...Evaluation.Discrete/Evaluation.Discrete.Classes.cs 94.73% 0 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2437      +/-   ##
==========================================
- Coverage   86.87%   86.86%   -0.01%     
==========================================
  Files         312      312              
  Lines       69724    69771      +47     
  Branches    20385    20403      +18     
==========================================
+ Hits        60570    60609      +39     
- Misses       4913     4918       +5     
- Partials     4241     4244       +3     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.41% <95.74%> (-0.01%) ⬇️
fsharp 32.97% <ø> (ø)
interactive 39.81% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...uriMath/Core/Entity/Continuous/Number/Operators.cs 90.07% <ø> (-0.80%) ⬇️
...nuous/Evaluation.Continuous.Arithmetics.Classes.cs 88.22% <100.00%> (+0.11%) ⬆️
...Evaluation.Discrete/Evaluation.Discrete.Classes.cs 90.04% <94.73%> (+0.45%) ⬆️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant